<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta http-equiv="Cache-Control" content="no-siteapp">
<link rel="stylesheet" href="../../../static/layui/css/layui.css" media="all" />
<link rel="stylesheet" href="../../../static/css/public.css" media="all" />
<link rel="stylesheet" href="../../../static/plugin/zTree/css/zTreeStyle/zTreeStyle.css" type="text/css">
</head>
<body class="childrenBody">
	<form class="layui-form">
		<blockquote class="layui-elem-quote quoteBox">
			<form class="layui-form">
				<div class="layui-inline">
					<label class="layui-form-label">所属部门</label>
					<div class="layui-input-inline">
						<input type="text" class="layui-input" id="dname" readonly lay-verify="required" placeholder=""> <input type="hidden" class="searchVal" name="did" id="did">
					</div>
					<a class="layui-btn" id="btn_treeClean">清空</a>
				</div>
				<div class="layui-inline">
					<label class="layui-form-label">日期</label>
					<div class="layui-input-block">
						<input type="text" class="layui-input searchVal" name="date" id="date"> <input type="hidden" class="layui-input searchVal" name="year" id="year"> <input type="hidden" class="layui-input searchVal" name="month" id="month">
					</div>
				</div>
			</form>
		</blockquote>
		<blockquote class="layui-elem-quote quoteBox">
			<div class="layui-inline">
				<a class="layui-btn search-btn" data-type="reload">搜索</a>
			</div>
		</blockquote>
		<table id="list" lay-filter="list"></table>
		<div class="list-page" id="page"></div>
	</form>
	<div id="treeDiv" class="menuContent" style="display: none; position: absolute; background: white; border: 1px black solid; z-index: 999">
		<ul id="departmentTree" class="ztree" style="margin-top: 0; width: 160px;"></ul>
	</div>
	<script type="text/javascript" src="../../../static/js/jquery-2.1.1.min.js"></script>
	<script type="text/javascript" src="../../../static/layui/layui.js"></script>
	<script type="text/javascript" src="../../../static/custom/js/common.js"></script>
	<script type="text/javascript" src="../../../static/plugin/zTree/js/jquery.ztree.core.js"></script>
	<script type="text/javascript">
		layui.use([ 'form', 'layer', 'table', 'laytpl', 'laydate' ], function() {
			var listApi = '../../../attendance/atdtable/listDepartment';
			var cols = [ [ {
				field : 'ername',
				title : '员工',
				align : "center"
			}, {
				field : 'dname',
				title : '部门',
				align : "center"
			}, {
				field : 'pname',
				title : '岗位',
				align : "center"
			}, {
				field : 'shouldAttd',
				title : '应出勤天数',
				align : 'center'
			}, {
				field : 'actualAttd',
				title : '实出勤天数',
				align : 'center'
			}, {
				field : 'paidAnnualLeave',
				title : '带薪年假天数',
				align : 'center'
			}, {
				field : 'paidLeave',
				title : '带薪调休天数',
				align : 'center'
			}, {
				field : 'generalLeave',
				title : '普通请假天数',
				align : 'center'
			}, {
				field : 'lateAndEarlyLeave',
				title : '迟到和早退分钟数',
				width : 150,
				align : 'center'
			}, {
				field : 'goout',
				title : '外出天数',
				align : 'center'
			}, {
				field : 'overtime',
				title : '加班小时数',
				align : 'center'
			}, {
				field : 'absenteeism',
				title : '旷工天数',
				align : 'center'
			}, {
				title : '是否已确认',
				align : 'center',
				templet : function(d) {
					return d.isConfirmed == 1 ? "已确认" : "未确认";
				}
			} ] ];
			var pram = merger(constant.page.toUri(), getsearchVal());
			var form = layui.form, layer = parent.layer === undefined ? layui.layer : top.layer;
			var $ = layui.jquery;
			var laytpl = layui.laytpl;
			var table = layui.table;
			var laydate = layui.laydate;
			var laypage = layui.laypage;
			tableIns = table.render({
				elem : '#list',
				cellMinWidth : constant.table.cellMinWidth,
				page : false,
				height : constant.table.height,
				cols : cols,
				done : function(res, page, count) {
					checkAll(form);
				}
			});

			//获取上一个月
			function getBeforeMonth() {
				var d = new Date();
				var currentYear = new Date().getFullYear();
				var currentMonth = new Date().getMonth() + 1;
				var beforeMonth = currentMonth - 1;
				if (beforeMonth == 0) {
					currentYear -= 1;
					beforeMonth = 12;
				}
				if (beforeMonth < 10) {
					beforeMonth = "0" + beforeMonth;
				}
				return {
					year : currentYear,
					month : beforeMonth
				};
			}
			//执行一个laydate实例
			laydate.render({
				elem : '#date',
				type : 'month',
				value : getBeforeMonth().year + "-" + getBeforeMonth().month,
				done : function(value, date, endDate) {
					$("#year").val(date.year);
					$("#month").val(date.month < 10 ? "0" + date.month : date.month);
				}
			});

			function listLoad(data) {
				loadAjax(listApi, "get", data, function(response) {
					baseCallBack(response, function(response) {
						table.reload("list", {
							data : response.data.records,
							limit : response.data.records.length
						//显示的数量
						})
						var page = laypage.render({
							elem : 'page',
							limits : constant.page.limits,
							limit : response.data.size,
							layout : constant.page.layout,
							curr : response.data.current,
							count : response.data.total,
							jump : function(obj, first) {
								if (!first) {
									pram = merger(constant.page.toUri(obj), getsearchVal());
									listLoad(pram);
								}
							}
						});
					});
				});
			}

			//搜索【此功能需要后台配合，所以暂时没有动态效果演示】
			$(".search-btn").on("click", function() {
				pram = merger(pram, getsearchVal());
				listLoad(pram);
			});

			//ztree
			var setting = {
				view : {
					dblClickExpand : false
				},
				data : {
					simpleData : {
						enable : true
					}
				},
				callback : {
					onClick : onClick
				}
			};

			function onClick(e, treeId, treeNode) {
				$("#did").val(treeNode.id);
				$("#dname").val(treeNode.name);
				hideMenu();
			}
			$("#btn_treeClean").click(function() {
				$("#did").val('');
				$("#dname").val('');
			})
			function showMenu() {
				var cityObj = $("#dname");
				var cityOffset = $("#dname").offset();
				$("#treeDiv").css({
					left : cityOffset.left + "px",
					top : cityOffset.top + cityObj.outerHeight() + "px"
				}).slideDown("fast");
				$("body").bind("mousedown", onBodyDown);
			}
			function hideMenu() {
				$("#treeDiv").fadeOut("fast");
				$("body").unbind("mousedown", onBodyDown);
			}
			function onBodyDown(event) {
				if (!(event.target.id == "treeSelect-btn" || event.target.id == "treeDiv" || $(event.target).parents("#treeDiv").length > 0)) {
					hideMenu();
				}
			}
			$("#dname").click(function() {
				showMenu()
			})
			loadAjax("../../../getDepartment", "get",  {
				"did" : cache.did.get()
			}, function(response) {
				baseCallBack(response, function(response) {
					$.fn.zTree.init($("#departmentTree"), setting, response.data);
				});
			});

		})
	</script>
</body>
</html>